package org.springframework.samples.mvc.basic.partner;

import org.springframework.samples.mvc.basic.business.Transformer;

import com.proba.annotations.pojo.Partner;
import com.proba.annotations.pojo.Sluzba;
import com.proba.annotations.pojo.TipPartner;

public class PartnerTransformer implements Transformer<Partner, PartnerView> {

	@Override
	public PartnerView transform(Partner entity) {
		PartnerView view = new PartnerView();
		view.setId(entity.getId());
		view.setPartner(entity.getPartner());
		view.setInvestitor(entity.getSluzba().getInvestitor());
		view.setTehnickiBroj(entity.getTehnickiBroj());
		view.setTipPartner(entity.getTipPartner().getTipPartner());
		return view;
	}

	@Override
	public Partner transform(PartnerView view) {
		Partner entity = new Partner();
		entity.setId(view.getId());
		entity.setPartner(view.getPartner());
		
		Sluzba sluzba = new Sluzba();
		sluzba.setId(Long.parseLong(view.getInvestitor()));
		entity.setSluzba(sluzba);
		
		entity.setTehnickiBroj(view.getTehnickiBroj());
		
		TipPartner tipPartner = new TipPartner();
		tipPartner.setId(Long.parseLong(view.getTipPartner()));
		entity.setTipPartner(tipPartner);
		return entity;
	}

}
